// 封装微信的 wx.showToast 方法 传入一个对象作为参数
const toast = ({ title = '数据加载中...', icon = 'none', duration = 2000, mask = true } = {}) => {
  wx.showToast({ title, icon, duration, mask })
}

// 封装微信的 wx.showModal 方法 传入一个对象作为参数
const modal = (options = {}) => {
  const params = Object.assign({ title: '提示', content: '您确定执行该操作吗?' }, options)
  return new Promise((resolve) => {
    wx.showModal({
      ...params,
      complete: ({ confirm, cancel }) => {
        confirm && resolve(true)
        cancel && resolve(false)
      }
    })
  })
}

const wxLogin = () => {
  return new Promise((resolve, reject) => {
    wx.login({ success: resolve, fail: reject });
  });
}

wx.toast = toast
wx.modal = modal
wx.wxLogin = wxLogin

export {
  toast,
  modal,
  wxLogin
}